/*
 * @Author: Tendo 
 * @Date: 2021-09-08 10:41:58
 * @param {ListNode} head
 * @return {ListNode}
 */
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
var swapPairs = (head) => {
    // 设置一个虚拟头节点
    const dummy = new ListNode(0, head);
    dummy.next = head; // 将虚拟头节点指向head，方便后面删除操作
    let cur = dummy;
    while(cur.next && cur.next.next) {
        // 记录临时节点
        let tmp = cur.next; 
        let tmp1 = cur.next.next.next;

        //调换相邻节点所需要的三个步骤
        cur.next = cur.next.next;
        cur.next.next = tmp;
        cur.next.next.next = tmp1;

        // cur 位移两位，准备下一轮交换
        cur = cur.next.next;
    }
    return dummy.next
}
